package com.viknix.threadpool.manager.client.util;

import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import javax.validation.Validation;
import javax.validation.Validator;
import java.util.Set;

/**
 * @Author: Dongqi
 * @Date: 2021/10/21 18:44
 * @Version 1.0
 * @Description: 校验工具
 */
public class ValidatorUtil {

    private static final Validator validator = Validation.buildDefaultValidatorFactory().getValidator();

    public static <T> void requiredParamCheck(T request) {
        Set<ConstraintViolation<T>> constraintViolations = validator.validate(request);
        if (constraintViolations.size() == 0) {
            return;
        }
        throw new ConstraintViolationException(constraintViolations);
    }
}
